package com.simple.common.utils;

import java.util.ArrayList;
import java.util.List;

public class EncryptUtil {
    public static String decode(String str) {
        String[] arr = str.split("%");
        char[] charArr = new char[arr.length];
        for(int i = 0; i < arr.length; ++i) {
            charArr[i] = (char)Integer.parseInt(arr[i]);
        }
        return String.valueOf(charArr);
    }

    public static String encode(String string){
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < string.length(); i++){
            list.add((int) string.charAt(i));
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            builder.append(list.get(i));
            if (i < list.size() - 1) {
                builder.append("%");
            }
        }

        return builder.toString();
    }


    public static String hidePhoneNumber(String phoneNumber){
        if(phoneNumber.length() == 11){
            return phoneNumber.substring(0,3) + "****" + phoneNumber.substring(7);
        }else {
            return phoneNumber;
        }
    }
}
